package edu.uic.kott.activities;

import java.util.List;

import edu.uic.keyoutcomestrackertool.R;
import edu.uic.kott.db.KottDataSource;
import edu.uic.kott.model.Instructor;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class Instructors extends ListActivity {

	private static final String LOGTAG = "KOTT";

	KottDataSource datasource;

	List<Instructor> allInstructorsTasList;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.view_instructors);

		datasource = new KottDataSource(this);		
	}

	public void refreshDisplay(){
		allInstructorsTasList = datasource.findAllInstructorsTas();

		ArrayAdapter<Instructor> instructorAdapter = new ArrayAdapter<Instructor>(this, android.R.layout.simple_list_item_1, allInstructorsTasList);
		setListAdapter(instructorAdapter);
	}
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);
		Instructor instructor = allInstructorsTasList.get(position);

		Log.i(LOGTAG,"Class Name clicked..opening Class Details");

		Intent intent = new Intent(this, InstructorDetails.class);
		intent.putExtra("instructorId", String.valueOf(instructor.getInstructorId()));
		startActivity(intent);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.menu_add, menu);		
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {	

		Intent intent = new Intent(this, AddEditInstructor.class);
		startActivity(intent);
		return true;
	}
	@Override
	protected void onResume() {
		refreshDisplay();
		super.onResume();
	}
}
